<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>moment(String) &#x591A;&#x4E2A;&#x683C;&#x5F0F; | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>moment(String) &#x591A;&#x4E2A;&#x683C;&#x5F0F;</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>moment(String) 多个格式</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/parsing/string-formats/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/01-parsing/04-string-formats.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment(String, String[], String, Boolean);
</code></pre>

							</div>
<p>&#x5982;&#x679C;&#x4E0D;&#x77E5;&#x9053;&#x8F93;&#x5165;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x786E;&#x5207;&#x683C;&#x5F0F;&#xFF0C;&#x4F46;&#x662F;&#x77E5;&#x9053;&#x5B83;&#x53EF;&#x80FD;&#x662F;&#x591A;&#x79CD;&#x683C;&#x5F0F;&#x4E4B;&#x4E00;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x683C;&#x5F0F;&#x6570;&#x7EC4;&#x3002;</p>
<p>&#x8FD9;&#x4E0E;<a href="javascript:window.open('http://nodejs.cn/s/2fw2Yx');" target="_blank" rel="nofollow">&#x5B57;&#x7B26;&#x4E32; + &#x683C;&#x5F0F;</a>&#x76F8;&#x540C;&#xFF0C;&#x53EA;&#x662F;&#x5B83;&#x5C06;&#x4F1A;&#x5C1D;&#x8BD5;&#x5C06;&#x8F93;&#x5165;&#x5339;&#x914D;&#x4E3A;&#x591A;&#x79CD;&#x683C;&#x5F0F;&#x3002;</p>
<pre><code class="language-js">moment(&quot;12-25-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;YYYY-MM-DD&quot;]);
</code></pre>
<p>&#x4ECE; <strong>2.3.0</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;Moment &#x4F7F;&#x7528;&#x4E00;&#x4E9B;&#x7B80;&#x5355;&#x7684;&#x8BD5;&#x63A2;&#x6CD5;&#x6765;&#x786E;&#x5B9A;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x683C;&#x5F0F;&#x3002;
&#x8FD9;&#x662F;&#x4E3A;&#x4E86;&#xFF1A;</p>
<ul>
<li>&#x4F18;&#x5148;&#x4F7F;&#x7528;&#x80FD;&#x751F;&#x6210;<a href="javascript:window.open('http://nodejs.cn/s/fmgsp6');" target="_blank" rel="nofollow">&#x6709;&#x6548;</a>&#x65E5;&#x671F;&#xFF08;&#x800C;&#x4E0D;&#x662F;&#x65E0;&#x6548;&#x65E5;&#x671F;&#xFF09;&#x7684;&#x683C;&#x5F0F;&#x3002;</li>
<li>&#x4F18;&#x5148;&#x4F7F;&#x7528;&#x80FD;&#x89E3;&#x6790;&#x66F4;&#x591A;&#xFF08;&#x800C;&#x4E0D;&#x662F;&#x66F4;&#x5C11;&#xFF09;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x683C;&#x5F0F;&#xFF0C;&#x4E14;&#x4F18;&#x5148;&#x4F7F;&#x7528;&#x89E3;&#x6790;&#x66F4;&#x591A;&#xFF08;&#x800C;&#x4E0D;&#x662F;&#x66F4;&#x5C11;&#xFF09;&#x7684;&#x683C;&#x5F0F;&#xFF0C;&#x5373;&#x4F18;&#x5148;&#x66F4;&#x4E25;&#x683C;&#x7684;&#x89E3;&#x6790;&#x3002;</li>
<li>&#x4F18;&#x5148;&#x4F7F;&#x7528;&#x5728;&#x6570;&#x7EC4;&#x4E2D;&#x524D;&#x9762;&#xFF08;&#x800C;&#x4E0D;&#x662F;&#x540E;&#x9762;&#xFF09;&#x7684;&#x683C;&#x5F0F;&#x3002;</li>
</ul>
<pre><code class="language-js">moment(&quot;29-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM&quot;, &quot;DD-MM-YYYY&quot;]); // &#x4F7F;&#x7528;&#x6700;&#x540E;&#x4E00;&#x79CD;&#x683C;&#x5F0F;&#x3002;
moment(&quot;05-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM-YYYY&quot;]);          // &#x4F7F;&#x7528;&#x7B2C;&#x4E00;&#x79CD;&#x683C;&#x5F0F;
</code></pre>
<p>&#x8FD8;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x548C;&#x4E25;&#x683C;&#x6027;&#x53C2;&#x6570;&#x3002;
&#x5B83;&#x4EEC;&#x7684;&#x5DE5;&#x4F5C;&#x65B9;&#x5F0F;&#x4E0E;&#x5355;&#x4E00;&#x683C;&#x5F0F;&#x7684;&#x60C5;&#x51B5;&#x76F8;&#x540C;&#x3002;</p>
<pre><code class="language-js">moment(&quot;29-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM-YYYY&quot;], &apos;fr&apos;);       // &#x4F7F;&#x7528; &apos;fr&apos; &#x8BED;&#x8A00;&#x73AF;&#x5883;&#x3002;
moment(&quot;29-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM-YYYY&quot;], true);       // &#x4F7F;&#x7528;&#x4E25;&#x683C;&#x7684;&#x89E3;&#x6790;&#x3002;
moment(&quot;05-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM-YYYY&quot;], &apos;fr&apos;, true); // &#x4F7F;&#x7528; &apos;fr&apos; &#x8BED;&#x8A00;&#x73AF;&#x5883;&#x548C;&#x4E25;&#x683C;&#x7684;&#x89E3;&#x6790;&#x3002;
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x89E3;&#x6790;&#x591A;&#x79CD;&#x683C;&#x5F0F;&#x6BD4;&#x89E3;&#x6790;&#x5355;&#x4E00;&#x683C;&#x5F0F;&#x8981;&#x6162;&#x5F97;&#x591A;&#x3002;
&#x5982;&#x679C;&#x53EF;&#x4EE5;&#x907F;&#x514D;&#xFF0C;&#x5219;&#x89E3;&#x6790;&#x5355;&#x4E00;&#x683C;&#x5F0F;&#x8981;&#x5FEB;&#x5F97;&#x591A;&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment(String, String[], String, Boolean);
</code></pre>

							</div>
<p>If you don&apos;t know the exact format of an input string, but know it could be one of many, you can use an array of formats.</p>
<p>This is the same as <a href="#/parsing/string-format/" target="_blank" rel="nofollow">String + Format</a>, only it will try to match the input to multiple formats.</p>
<pre><code class="language-js">moment(&quot;12-25-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;YYYY-MM-DD&quot;]);
</code></pre>
<p>Starting in version <strong>2.3.0</strong>, Moment uses some simple heuristics to determine which format to use. In order:</p>
<ul>
<li>Prefer formats resulting in <a href="#/parsing/is-valid/" target="_blank" rel="nofollow">valid</a> dates over invalid ones.</li>
<li>Prefer formats that parse more of the string than less and use more of the format than less, i.e. prefer stricter parsing.</li>
<li>Prefer formats earlier in the array than later.</li>
</ul>
<pre><code class="language-js">moment(&quot;29-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM&quot;, &quot;DD-MM-YYYY&quot;]); // uses the last format
moment(&quot;05-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM-YYYY&quot;]);          // uses the first format
</code></pre>
<p>You may also specify a locale and strictness argument. They work the same as the single format case.</p>
<pre><code class="language-js">moment(&quot;29-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM-YYYY&quot;], &apos;fr&apos;);       // uses &apos;fr&apos; locale
moment(&quot;29-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM-YYYY&quot;], true);       // uses strict parsing
moment(&quot;05-06-1995&quot;, [&quot;MM-DD-YYYY&quot;, &quot;DD-MM-YYYY&quot;], &apos;fr&apos;, true); // uses &apos;fr&apos; locale and strict parsing
</code></pre>
<p><strong>Note:</strong> Parsing multiple formats is considerably slower than parsing a single format. If you can avoid it, it is much faster to parse a single format.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>